package com.cuijq.ms.statedesign.v3;

import static com.cuijq.ms.statedesign.v3.State.CAPE;
import static com.cuijq.ms.statedesign.v3.State.FIRE;
import static com.cuijq.ms.statedesign.v3.State.SMALL;
import static com.cuijq.ms.statedesign.v3.State.SUPER;

/**
 * @author by CuiJQ
 * @Classname MarioStateMachine
 * @Description MarioStateMachine Description
 * @Date 2021/5/29 15:18
 */
public class MarioStateMachine {

  private int score;
  private State currentState;

  public MarioStateMachine() {
    this.score = 0;
    this.currentState = SMALL;
  }

  private static final State[][] transitionTable = {{SUPER, CAPE, FIRE, SMALL}, {SUPER, CAPE, FIRE, SMALL},
      {CAPE, CAPE, CAPE, SMALL}, {FIRE, FIRE, FIRE, SMALL}};
  private static final int[][] actionTable = {{+100, +200, +300, +0}, {+0, +200, +300, -100}, {+0, +0, +0, -200},
      {+0, +0, +0, -300}};

  public void obtainMushRoom() { //TODO
    executeEvent(Event.GOT_MUSHROOM);
  }

  public void obtainCape() { //TODO
    executeEvent(Event.GOT_CAPE);
  }

  public void obtainFireFlower() { //TODO
    executeEvent(Event.GOT_FIRE);
  }

  private void executeEvent(java.awt.Event event) {
    executeEvent(Event.MET_MONSTER);
  }


  private void executeEvent(Event event) {
    int stateValue = currentState.getValue();
    int eventValue = event.getValue();
    this.currentState = transitionTable[stateValue][eventValue];
    this.score += actionTable[stateValue][eventValue];
  }

  public int getScore() {
    return this.score;
  }

  public State getCurrentState() {
    return this.currentState;
  }
}
